<template>
  <div>
    <div class="sign_do">
      
         <el-divider></el-divider>
      <el-button type="primary" @click="dialogFormVisible = true">签到</el-button>
      <el-button type="primary" @click="dialogFormVisible = true">签退</el-button>
      

    </div>
    
  
  </div>
</template>


<script>
import logapi from '@/api/login'
 import signApi  from '@/api/sign/sign'
import { getToken } from '../../../../utils/auth'

export default {

  data(){
    return {
      stuId:'',
      classid:''
    } 
  },
  created(){
   var startData = new Date();
   var year = startData.getFullYear();
   var month = startData.getMonth()+1;
   var date = startData.getDate();
   let hh = startData.getHours();
   let mf = startData.getMinutes()<10 ? '0'+startData.getMinutes() : startData.getMinutes();
   let ss = startData.getSeconds()<10 ? '0'+startData.getSeconds() : startData.getSeconds();
  
   this.getStudentInfo()

  },
  methods:{
    getStudentInfo(){
      logapi.getUserName(getToken())
      .then(response=>{
        this.stuId = response.data;
        this.StudentSign()
        this. StudentSignBake()
      
      })
    },
    StudentSign(){
      var data = new Date();
      signApi.getIsSign(this.stuId)
      .then(response=>{
        if(response.date){
          this.sign()
        }
        
      })
     

      
      
    },
    StudentSignBake(){
      var data = new Date();
      signApi.getIsSignBack(this.stuId)
      .then(response=>{
        this.signback()
      })
     

      
      
    },
    sign(){
       this.$confirm('是否签到?', '签到成功', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          console.log("78787")
         
           signApi.StudentSign(this.stuId)
            .then(response =>{
               this.$message({
            type: 'success',
            message: '签到成功!'
          });

          })  
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    signback(){
       this.$confirm('是否签退?', '签退成功', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          console.log("78787")
         
           signApi.StudentSignBack(this.stuId)
            .then(response =>{
               this.$message({
            type: 'success',
            message: '签退成功!'
          });

          })  
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    


    
  }
}
</script>
